import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class CompanyLoginServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {

       String company_uname=request.getParameter("company_uname");
        String company_pwd=request.getParameter("company_pwd");
String str="";
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();


        Class.forName("oracle.jdbc.driver.OracleDriver");
       Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 
     
       Statement stmt=con.createStatement();
         
		 
       ResultSet rs = stmt.executeQuery("SELECT *FROM company_login WHERE company_uname='"+company_uname+"' and company_pwd='"+company_pwd+"'");

    
         if(rs.next())

         {
           
         ResultSet rs2=stmt.executeQuery("SELECT *FROM company_register WHERE company_uname='" +company_uname+ "'");

 
    while(rs2.next())
     {
             String company_name = rs2.getString(1);
             String website = rs2.getString(2);
             String email = rs2.getString(3);                                    
             String tel_no = rs2.getString(4);                                    
     
 
     out.println("<html>");
     
     out.println("<body background=\"t11.jpg\">");
  out.println("<div><div style='float:left'>");
out.println("<form action='index.html'>");
 out.println("<input type='submit' value='home'/></form></div>");
out.println("<div style='float:right'>");
 out.println("<form action='company-login.html'>");
            out.println("<input type='submit'  value='logout'/></form></div>");
            
     out.println("<center>");    
     
     out.println(" <br><h1> <font color=\"red\"> "+company_name+" </font> </h1> ");

     out.println("<br> <b> Website: <font color=\"navy\"> "+ website +" </font> </b>");
     out.println(" <br> <b> email : <font color=\"navy\">"+ email+ "</font> </b> ");
     out.print("&nbsp &nbsp &nbsp <b> Tel No: <font color=\"navy\">"+ tel_no+ "</font></b>");

   out.println("<br> <br>  <b> <marquee> <font size=\"3\" color=\"navy\"> Placement Assistance for </font> <font color=\"red\" size=\"4\"> "+company_name+"</font> </marquee> </b>");

     out.println("</center>");   
      ResultSet rs5=stmt.executeQuery("select college_name from college_register");
         while(rs5.next())
		  {
		  String s=rs5.getString("college_name");
		  str=str+"<option value='"+s+"'>"+s+"</option>";

		  }

out.println("<div style='float:right;width:35%'>");
            out.println("<form method='post' action='ccs2'>");
            out.println(" <font color=\"white\">search foe college: </font><select name='college' id='college' ><option value='--select--'>--select--</option>"+str+"</select>  <input type='submit' value='search'/></form>"); 
         out.println("</div>");
         //out.println("<form action='spam.jsp' method='post'>");
        // out.println("<input type='hidden' name='company_name' value='"+company_name+"'/>");
        // out.println("<input type='submit' value='spam'/></form>");
         out.println("<a href=mail.html><font color='CCFF66' size='5'/>Send Message</a>");
         out.println("<br><blink><b><font color='#ffa639' size='6'/>UPDATES</b></blink>");
         ResultSet rs6=stmt.executeQuery("select student_name from register_job where company_name='"+company_name+"'");
         out.println("<center><table border='1'width='80%'bgcolor='#e0ccff' >");
         
         while(rs6.next())
		  {
		  String student_name=rs6.getString("student_name");
		  
      out.println("<tr><td>");
       
         out.println("<font color='black' size='5'><center>");
        
        
          out.println(student_name+"</center>");
          out.println("</td><td>");
           out.println("<font color='black'size='5'><center> a registration form submittted by student:");
         out.println("</center></font></td><td>");
         out.println("<form action='cm' method='post' >"+"<input type='hidden'  name='company_name' value='"+company_name+"'>");
     out.println("<input type='submit' value='checkhere'/></form></center></td></tr>");
     
                  }
         
    out.println("</table></center>");
     out.println("</body>");

     out.println("</html>");        

     }

  }

         else

       {
                      
           out.println("<html>");
     
           out.println("<body background=\"t11.jpg\">");

           out.println(" <font size=\"4\"> ");
        
           out.println("<br><br> <b> Invalid Username/password </b>");
  

           out.println("<br><br> <b> <a href=\"company-login.html\"> <font color=\"blue\"> Click </font> </a> here to reenter the Correct Username and Password </b>");

           out.println(" </font> ");
    
           out.println("</body>");

           out.println("</html>");        
  
       }

    }
 
    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 